home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/bin/sh set -e CMD=$(basename ${0}) LOCK=/var/lock/${CMD} . gettext.sh TEXTDOMAIN="${CMD}" export TEXTDOMAIN ROFS=/live/rofs/filesystem.squashfs CONF_DIR=/var/lib/unsafe-browser COW=${CONF_DIR}/cow CHROOT=${CONF_DIR}/chroot CLEARNET_USER=clearnet OFFENDING_ADDONS="xul-ext-foxyproxy-standard xul-ext-torbutton xul-ext-firegpg xul-ext-cookie-monster xul-ext-noscript xul-ext-monkeysphere" # Import tor_is_working() . /usr/local/lib/tails-shell-library/tor.sh WARNING_PAGE='/usr/share/doc/tails/website/misc/unsafe_browser_warning' LANG_CODE="$(echo ${LANG} | head -c 2)" if [ -r "${WARNING_PAGE}.${LANG_CODE}.html" ]; then START_PAGE="${WARNING_PAGE}.${LANG_CODE}.html" else START_PAGE="${WARNING_PAGE}.en.html" fi if [ -e /var/lib/gdm3/tails.camouflage ]; then CAMOUFLAGE=yes fi cleanup () { # Break down the chroot and kill all of its processes local counter=0 local ret=0 while [ "${counter}" -le 10 ] && \ pgrep -u ${CLEARNET_USER} 1>/dev/null 2>&1; do pkill -u ${CLEARNET_USER} 1>/dev/null 2>&1 ret=${?} sleep 1 counter=$((${counter}+1)) done [ ${ret} -eq 0 ] || pkill -9 -u ${CLEARNET_USER} 1>/dev/null 2>&1 for mnt in ${CHROOT}/dev ${CHROOT}/proc ${CHROOT} ${COW}; do counter=0 while [ "${counter}" -le 10 ] && mountpoint -q ${mnt} 2>/dev/null; do umount ${mnt} 2>/dev/null sleep 1 counter=$((${counter}+1)) done done rmdir ${COW} ${CHROOT} 2>/dev/null } error () { local cli_text="${CMD}: `gettext \"error:\"` ${@}" local dialog_text="<b><big>`gettext \"Error\"`</big></b> ${@}" echo "${cli_text}" >&2 sudo -u ${SUDO_USER} zenity --error --title "" --text "${dialog_text}" exit 1 } warning () { local cli_text="${CMD}: `gettext \"warning:\"` ${text}" local dialog_text="<b><big>`gettext \"Warning\"`</big></b> ${@}" echo "${cli_text}" >&2 sudo -u ${SUDO_USER} zenity --warning --title "" --text "${dialob_text}" } verify_start () { # Make sure the user really wants to start the browser local dialog_msg="<b><big>`gettext \"Do you really want to launch the Unsafe Browser?\"`</big></b> `gettext \"Network activity within the Unsafe Browser is <b>not anonymous</b>. Only use the Unsafe Browser if necessary, for example if you have to login or register to activate your Internet connection.\"`" local launch="`gettext \"_Launch\"`" local exit="`gettext \"_Exit\"`" # Since zenity can't set the default button to cancel, we switch the # labels and interpret the return value as its negation. if sudo -u ${SUDO_USER} zenity --question --title "" --ok-label "${exit}" \ --cancel-label "${launch}" --text "${dialog_msg}"; then exit 0 fi } show_start_notification () { local title="`gettext \"Starting the Unsafe Browser...\"`" local body="`gettext \"This may take a while, so please be patient.\"`" notify-send -t 10000 "${title}" "${body}" } setup_chroot () { # Setup a chroot on an aufs "fork" of the filesystem. # FIXME: When LXC matures to the point where it becomes a viable option # for creating isolated jails, the chroot can be used as its rootfs. echo "* Setting up chroot" trap cleanup INT trap cleanup EXIT mkdir -p ${COW} ${CHROOT} && \ mount -t tmpfs tmpfs ${COW} && \ mount -t aufs -o noatime,noxino,dirs=${COW}=rw:${ROFS}=rr+wh aufs ${CHROOT} && \ mount -t proc proc ${CHROOT}/proc && \ mount --bind /dev ${CHROOT}/dev || \ error "`gettext \"Failed to setup chroot.\"`" } set_chroot_browser_name () { NAME="${1}" LONG=$(echo ${LANG} | grep -o "^[a-zA-Z_]*") SHORT=${LONG%%_*} EXT_DIR=${CHROOT}/usr/lib/iceweasel/extensions BRANDING=branding/brand.dtd if [ -e "${EXT_DIR}/langpack-${LONG}@iceweasel.mozilla.org.xpi" ]; then PACK="${EXT_DIR}/langpack-${LONG}@iceweasel.mozilla.org.xpi" TOP=chrome REST=${LONG}/locale elif [ -e "${EXT_DIR}/langpack-${SHORT}@iceweasel.mozilla.org.xpi" ]; then PACK="${EXT_DIR}/langpack-${SHORT}@iceweasel.mozilla.org.xpi" TOP=chrome REST=${SHORT}/locale else PACK=${CHROOT}/usr/share/iceweasel/chrome/en-US.jar TOP=locale REST= fi TMP=$(mktemp -d) 7z x "${PACK}" -o"${TMP}" sed -i "s/Iceweasel/${NAME}/" "${TMP}"/"${TOP}"/"${REST}"/"${BRANDING}" 7z u -tzip "${PACK}" "${TMP}"/"${TOP}" chmod a+r "${PACK}" rm -Rf "${TMP}" } configure_chroot () { echo "* Configuring chroot" # Set the chroot's DNS servers to those obtained through DHCP rm -f ${CHROOT}/etc/resolv.conf for NS in ${IP4_NAMESERVERS}; do echo "nameserver ${NS}" >> ${CHROOT}/etc/resolv.conf done chmod a+r ${CHROOT}/etc/resolv.conf # Remove all Iceweasel addons: some adds proxying, which we don't # want; some may change the fingerprint compared to a standard # Iceweasel install. chroot ${CHROOT} apt-get remove --yes xul-ext-* # Disable proxying in the chroot sed -i '/^pref("network.proxy.type",/d' \ ${CHROOT}/etc/iceweasel/pref/iceweasel.js echo 'pref("network.proxy.type", 0);' >> \ ${CHROOT}/etc/iceweasel/pref/iceweasel.js rm -rf ${CHROOT}/etc/iceweasel/profile/extensions # Set a scary theme (except if we're using Windows camouflage) if [ -z "${CAMOUFLAGE}" ]; then cat >> ${CHROOT}/etc/iceweasel/profile/user.js <<EOF user_pref("lightweightThemes.isThemeSelected", true); user_pref("lightweightThemes.usedThemes", "[{\"id\":\"1\",\"name\":\"Unsafe Browser\",\"headerURL\":\"file:///usr/share/pixmaps/red_dot.png\",\"footerURL\":\"file:///usr/share/pixmaps/red_dot.png\",\"textcolor\":\"#FFFFFF\",\"accentcolor\":\"#CC0000\",\"updateDate\":0,\"installDate\":0}]"); EOF else echo "LIVE_USERNAME=${CLEARNET_USER}" > \ ${CHROOT}//etc/live/config.d/username.conf chroot ${CHROOT} tails-activate-winxp-theme fi # Set the name (e.g. window title) of the browser set_chroot_browser_name "`gettext \"Unsafe Browser\"`" # Set start page to something that explains what's going on echo 'user_pref("browser.startup.homepage", "'${START_PAGE}'");' >> \ ${CHROOT}/etc/iceweasel/profile/user.js # Remove all bookmarks rm -f ${CHROOT}/etc/iceweasel/profile/bookmarks.html # Make the English wikipedia the only available and default search # engine (this is a documented cue for identifying the Unsafe Browser, # which is extra important in camouflage mode when the scary coloured # theme is disabled.) find ${CHROOT}/etc/iceweasel/profile/searchplugins/ \ ${CHROOT}/etc/iceweasel/searchplugins -name "*.xml" | \ while read searchengine; do if basename "$searchengine" | grep -qvi wikipedia; then rm "${searchengine}" fi done sed -i '/^user_pref("browser.search.defaultenginename",/d' \ ${CHROOT}/etc/iceweasel/profile/user.js echo 'user_pref("browser.search.defaultenginename", "Wikipedia (en)");' >> \ ${CHROOT}/etc/iceweasel/profile/user.js sed -i '/^user_pref("browser.search.selectedEngine",/d' \ ${CHROOT}/etc/iceweasel/profile/user.js echo 'user_pref("browser.search.selectedEngine", "Wikipedia (en)");' >> \ ${CHROOT}/etc/iceweasel/profile/user.js } run_browser_in_chroot () { # Start Iceweasel in the chroot echo "* Starting Unsafe Browser" sudo -u ${SUDO_USER} xhost +SI:localuser:${CLEARNET_USER} 2>/dev/null chroot ${CHROOT} sudo -u ${CLEARNET_USER} iceweasel -DISPLAY=:0.0 sudo -u ${SUDO_USER} xhost -SI:localuser:${CLEARNET_USER} 2>/dev/null } show_shutdown_notification () { local title="`gettext \"Shutting down the Unsafe Browser...\"`" local body="`gettext \"This may take a while, and you may not restart the Unsafe Browser until it is properly shut down.\"`" notify-send -t 10000 "${title}" "${body}" } maybe_restart_tor () { # Restart Tor if it's not working (a captive portal may have prevented # Tor from bootstrapping, and a restart is the fastest way to get # wheels turning) if ! tor_is_working; then echo "* Restarting Tor" restart-tor if ! service tor status >/dev/null; then error "`gettext \"Failed to restart Tor.\"`" fi fi } # Prevent multiple instances of the script. exec 9>${LOCK} if ! flock -x -n 9; then error "`gettext \"Another Unsafe Browser is currently running, or being cleaned up. Please retry in a while.\"`" fi # Get the DNS servers that was obtained from NetworkManager, if any... NM_ENV=/var/lib/NetworkManager/env if [ -r "${NM_ENV}" ]; then . ${NM_ENV} fi # ... otherwise fail. # FIXME: Or would it make sense to fallback to Google's DNS or OpenDNS? # Some stupid captive portals may allow DNS to any host, but chances are # that only the portal's DNS would forward to the login page. if [ -z "${IP4_NAMESERVERS}" ]; then error "`gettext \"No DNS server was obtained through DHCP or manually configured in NetworkManager.\"`" fi verify_start show_start_notification setup_chroot configure_chroot run_browser_in_chroot show_shutdown_notification maybe_restart_tor exit 0